package behavior.mediator;

import behavior.mediator.country.InternationalRelations;
import behavior.mediator.country.ShuguoInternational;
import behavior.mediator.country.WeiguoInternational;
import behavior.mediator.country.WuguoInternational;

import java.util.LinkedList;
import java.util.List;

/**
 * 信使实现
 */
public class MessengerImpl implements Messenger{

    /**
     * 信使集合
     **/
    public static List<InternationalRelations>  relationsList = new LinkedList<>();

    public MessengerImpl(){
        if (relationsList.size() == 0){
            relationsList.add(new ShuguoInternational());
            relationsList.add(new WeiguoInternational());
            relationsList.add(new WuguoInternational());
        }
    }

    @Override
    public void inform(InternationalRelations relations, String message) {
        System.out.println("通报消息");
        relations.sendMessage(message);

        for (InternationalRelations internationalRelations : relationsList) {
            if (!internationalRelations.sign().equals(relations.sign()) ) {
                internationalRelations.getMessage(message);
            }
        }
    }


}
